// 加载公共样式
require('../../assets/css/common.less')
// 自己的样式
require('./run.less')
//引入tabbar渲染函数
const renderTabbar=require('../../utils/tabbar')
//axios工具类
const request = require('../../utils/request')
  //服务器地址
  const API = 'http://fitness.h5.itsource.cn:3701'
// 点击事件
let navgRunning = document.querySelector('.navg-running')
let navgRiding = document.querySelector('.navg-riding')
let navgTraining = document.querySelector('.navg-training')
let navgtxt = document.querySelectorAll('.navgtxt')
let maintxt = document.querySelectorAll('.maintxt')
let ddv1=document.querySelector('.ddv1')
let dv=document.querySelector('.dv')
const maintraining=document.querySelector('.main-training')
const mainriding=document.querySelector('.main-riding')
const mainrunning=document.querySelector('.main-running')
const go=document.querySelector('.go')
let page=0;
// console.log(location.search);
page=location.search.split('=')[1]
console.log(page);

// navgRunning.addEventListener('click',function(){
//     console.log(22);

// })
window.onload=()=>{
  let map = new AMap.Map('container', {
    zoom:15,//级别
    center: [104.05843,30.53565],//中心点坐标
    viewMode:'3D'//使用3D视图
});
AMap.plugin(['AMap.ToolBar','AMap.Driving'],function(){//异步同时加载多个插件
  var toolbar = new AMap.ToolBar();
  map.addControl(toolbar);
  var driving = new AMap.Driving();//驾车路线规划
  driving.search(/*参数*/)
});
// ------------------骑行的地图-----------------
let map2 = new AMap.Map('container2', {
  zoom:15,//级别
  center: [104.05843,30.53565],//中心点坐标
  viewMode:'3D'//使用3D视图
});
AMap.plugin(['AMap.ToolBar','AMap.Driving'],function(){//异步同时加载多个插件
var toolbar = new AMap.ToolBar();
map2.addControl(toolbar);
var driving = new AMap.Driving();//驾车路线规划
driving.search(/*参数*/)
});

  if(page==3){
    console.log(2222);
    navgRiding .classList.remove('runactive')
    navgRunning.classList.remove('runactive')
    navgTraining .classList.add('runactive')
    mainriding.classList.add('dpnone')
    maintraining.classList.remove('dpnone')
    mainrunning.classList.add('dpnone')

  }
  // 点击go去到倒计时界面
  go.addEventListener('click',()=>{
    location.href='./sporting.html'
  })

  
    // 渲染底部tabbar
    renderTabbar()
    // 导航栏点击事件
    navgtxt.forEach(function (v, i) {
        let n = 0
        v.addEventListener('click', function () {
            // console.log(i);
            maintxt.forEach(function (dom, index) {
                dom.classList.add('dpnone')
                navgtxt[index].classList.remove('runactive')
            })
            maintxt[i].classList.remove('dpnone')
            v.classList.add('runactive')
        })
    
    
    })
   


    // /获取数据
    function getData() {
        request.get('/api/train/courseList').then(res=>{
            // console.log(res.data);
            let {errno,data}=res.data
            if(errno===0){
                render(data)
            }

        })

    }
    getData()
    function render(data) {
      // console.log(data);
      let data1=data[0]
      // console.log(data1);
      let html1=`
      <a href='./course-detail.html?id=${data1.courseId}' class="new-course">
      <h3 class="txt">最新课程</h3>
      <div class="panl">
        <img id="img1" src="${API + data1.imgurl}" >
        <p class="txt2">${data1.name}</p>
        <p class="txt3">${data1.desc}</p>
       
      </div>
      </a>
      `
      ddv1.innerHTML=html1;
       //获取课程列表数据
       const data2=data.filter((v,i)=>{
         return i!==0
       })
       console.log(data2);
       let html2=`
       ${
          data2.map(v=>
              ` <a href="./course-detail.html?id=${v.courseId}" class="course-item">
              <img src="${API+v.imgurl}" class="img" />
              <div class="info">
                <div class="title">${v.name}</div>
                <div class="desc ">${v.desc}</div>
              </div>
            </a>
              `
  
          ).join('')
  
          
      }
       `
       dv.innerHTML=html2
  }

}

